//
//  WLCustomerAlearView.m
//  WLDD
//

//

#import "ZDBCustomerAlearView.h"
@interface ZDBCustomerAlearView()
#pragma make --控件
@property(nonatomic,strong)UIView * bgView;
@property(nonatomic,strong)UILabel * titleLab;
@property(nonatomic,strong)UILabel * contentLab;


@end
@implementation ZDBCustomerAlearView
- (instancetype)initWithtititle:(NSString *)title
                         content:(NSString *)content
                          cancel:(NSString *)cancel
                         submit:(NSString *)submit;
{
    if (self=[super init])
    {
        self.frame=[UIScreen mainScreen].bounds;
        self.backgroundColor=[UIColor colorWithWhite:.0 alpha:.6];

        [self addSubview:self.bgView];
        [_bgView addSubview:self.titleLab];
        [_bgView addSubview:self.contentLab];
        [_bgView addSubview:self.cancelBtn];
        [_bgView addSubview:self.submitBtn];
        _titleLab.text = title;
        _contentLab.text = content;
        [_cancelBtn setTitle:cancel forState:0];
        [_submitBtn setTitle:submit forState:0];
        
    }
    return self;
}

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RealValue_W(540), RealValue_W(420))];
        _bgView.center =self.center;
        _bgView.backgroundColor=WHITECOLOR;
        KViewRadius(_bgView, 4);
    }
    return _bgView;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _bgView.width, 40)];
        _titleLab.font = AutoBoldFont(16);
        _titleLab.textColor = MAINTITLECOLOR;
        _titleLab.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLab;
}
- (UILabel *)contentLab
{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] initWithFrame:CGRectMake(20, _titleLab.bottom, _bgView.width-40, 100)];
        _contentLab.font = AutoFont(14);
        _contentLab.textColor = MAINTITLECOLOR;
        _contentLab.textAlignment = NSTextAlignmentCenter;
        _contentLab.numberOfLines = 0;
    }
    return _contentLab;
}

- (UIButton *)cancelBtn
{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(RealValue_H(30) , _bgView.height - RealValue_W(92), RealValue_W(210), RealValue_W(60))];
        
        _cancelBtn.titleLabel.font = AutoBoldFont(12);
        [_cancelBtn setTitleColor:TABTITLECOLOR forState:0];
        [_cancelBtn addTarget:self action:@selector(cancelClick) forControlEvents:(UIControlEventTouchUpInside)];
       KViewRadius(_cancelBtn, RealValue_W(30));
       KViewBorder(_cancelBtn, TABTITLECOLOR, 1);
    }
    return _cancelBtn;
}
- (UIButton *)submitBtn
{
    if (!_submitBtn) {
        _submitBtn = [[UIButton alloc] initWithFrame:CGRectMake(_bgView.width - RealValue_H(30) -RealValue_W(210) , _bgView.height - RealValue_W(92), RealValue_W(210), RealValue_W(60))];
        [_submitBtn setTitleColor:WHITECOLOR forState:0];
        _submitBtn.titleLabel.font = AutoBoldFont(12);
        KViewRadius(_submitBtn, RealValue_W(30));
        _submitBtn.backgroundColor = TABTITLECOLOR;
        [_submitBtn addTarget:self action:@selector(submitBtn:) forControlEvents:(UIControlEventTouchUpInside)];
       
    }
    return _submitBtn;
}
- (void)submitBtn:(UIButton *)sender
{
    
}
- (void)cancelClick
{
    [self dismissAlertView];
}
- (void)dismissAlertView
{
    [self removeFromSuperview];
}
-(void)showLXAlertView
{
    [kWindow addSubview:self];
    [self setShowAnimation];
}
-(void)setShowAnimation{
    WeakSelf;
    switch (_animationStyle) {
            
        case LXASAnimationDefault:
        {
            [UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                [weakSelf.bgView.layer setValue:@(0) forKeyPath:@"transform.scale"];
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.23 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    [weakSelf.bgView.layer setValue:@(1.2) forKeyPath:@"transform.scale"];
                } completion:^(BOOL finished) {
                    [UIView animateWithDuration:0.09 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                        [weakSelf.bgView.layer setValue:@(.9) forKeyPath:@"transform.scale"];
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:0.05 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                            [weakSelf.bgView.layer setValue:@(1.0) forKeyPath:@"transform.scale"];
                        } completion:^(BOOL finished) {
                            weakSelf.userInteractionEnabled = YES;
                        }];
                    }];
                }];
            }];
        }
            break;
            
        case LXASAnimationLeftShake:{
            
            CGPoint startPoint = CGPointMake(-_bgView.width, self.center.y);
            weakSelf.bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationTopShake:{
            
            CGPoint startPoint = CGPointMake(self.center.x, -_bgView.frame.size.height);
            _bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationNO:{
            
        }
            
            break;
            
        default:
            break;
    }
}
@end
